package com.xishu.service.print.kitchen;

import com.xishu.entity.hardware.Printer;
import com.xishu.entity.order.Order;
import com.xishu.service.ShopService;
import com.xishu.util.Tools;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.impl.ChainBase;

import java.util.List;

public class ListPrinterCmd implements Command, Tools {
    private Order orderInDb;
    private List<Long> orderItemIdList;

    public ListPrinterCmd(Order orderInDb, List<Long> orderItemIdList) {
        this.orderInDb = orderInDb;
        this.orderItemIdList = orderItemIdList;
    }

    @Override
    public boolean execute(Context context) throws Exception {
        ChainBase chainBase = new ChainBase();

        //有几个打印机，就添加几个打印机的任务
        List<Printer> allShopPrinterList = ShopService.getInstance().findAllShopPrinters(orderInDb.getShopId());
        for (Printer printer : allShopPrinterList) {
            chainBase.addCommand(new PrinterOrderCmd(printer, orderInDb, orderItemIdList));
        }

        return chainBase.execute(context);
    }
}
